<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
    xmlns:kiwi="http://www.kiwi-project.eu/jsf"
    xmlns:c="http://java.sun.com/jstl/core"
	xmlns:a="http://richfaces.org/a4j">


	    <!-- fragments in the view. (needs to be included outside the form, for it has its own inside.)  -->
	    <ui:include src="/dialogs/fragments.xhtml" />


		<style>
	        .inplace{
	            border: none;
	            cursor:pointer; 
	        }
	        .hover {
	            color: #{a4jSkin.generalTextColor};
	            background-color :#{a4jSkin.tipBorderColor};
	        }   
		   
	    </style> 
		
		<div id="rating"></div>
		<br />
		
		<!-- 
        <script>
	        jQuery(document).ready(function(){
		        jQuery('#rating').rating({
		            label:		   'Rating: ',
                    uri:           '#{currentContentItem.resource.uri}',
				    user:          '#{currentUser.login}',
				    webServiceUrl: '#{facesContext.externalContext.requestContextPath}/seam/resource/services/widgets/rating'
				});
	        });  
        </script>
 		-->
		<!-- Display fragments in the view.  -->
        <script type="text/javascript">
// <![CDATA[        
            fragmentJSLib={};
            fragmentJSLib.showFragmentsPanel = function (context, fragment) {
                var argString = 
                        (context == null ? "" : context) + " " + 
                        (fragment == null ? "" : fragment);
                
                fragmentSet(argString);
                #{rich:component('fragmentsPanel')}.show();
            }
            
            fragmentJSLib.onCreateOrUpdate = function (fragmentJS) {
                #{rich:component('fragmentsPanel')}.hide();
            }
            
            fragmentJSLib.onCancel = function () {
                #{rich:component('fragmentsPanel')}.hide();
            }

            fragmentJSLib.onDelete = function () {
                #{rich:component('fragmentsPanel')}.hide();
            }

			setFragmentStyle = function(id, style) {
				var spans = document.getElementsByTagName("span");
				for (var i = 0; i < spans.length; ++i) {
					var span = spans[i];
					if (span.hasAttribute("fragment_ids")) {
						var ids = span.getAttribute("fragment_ids").split(" ");
						for (var j = 0; j < ids.length; ++j) {
							if (ids[j] == id) {
								for (var property in style) {
									span.style[property] = style[property];
								}
							}
						}
					}
				}
			};

        	jQuery(document).ready(function(){
				var bookmarks = document.getElementsByTagName("kiwi:bookmarkstart");
				for (var i = 0; i < bookmarks.length; i++) { 
					var bookmark = bookmarks[i];

					var img = document.createElement("img");
					img.setAttribute("src", "img/bullet.gif");
					// img.appendChild(document.createTextNode("[fragment]"));

					bookmark.appendChild (img);

					jQuery(img).click(function(eventObject) {
						var id = this.parentNode.getAttribute("id");
						// TODO: get the context as the nearest "about" element...
						fragmentJSLib.showFragmentsPanel(null, id);
					});

					jQuery(img).hover(function() {
						var id = this.parentNode.getAttribute("id");
						setFragmentStyle(id, {backgroundColor:"#8bc53e"});
					},function() {
						var id = this.parentNode.getAttribute("id");
					    setFragmentStyle(id, {backgroundColor:null});	
					});
				}
            });
// ]]>
        </script>
		
        <!-- include resource from webservice so that we can support JSF tags inside the content -->
        
        <kiwi:renderHtml contentItem="#{contentItem}" currentUser="#{currentUser}"/>     
        <kiwi:microformats contentItem="#{contentItem}"/>
	        
	    <!--  commenting functionality 
	    <hr style="clear:left;" />
        <ui:include src="/panels/commenting.xhtml">
			<ui:param name="editable" value="true" />
		</ui:include>-->

</ui:composition>
